package com.example.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.ChatMessage;
import com.example.entity.Result;
import com.example.service.ChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/msg")
@CrossOrigin
public class ChatMsgController {

    @Autowired
    private ChatMessageService chatMessageService;

    @GetMapping("/get")
    public Result<List<ChatMessage>> getMsg(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") String pageSize) {
        System.out.println("get");
        List<ChatMessage> list = chatMessageService.ListPage2(pageNo,pageSize);
        System.out.println(list);
        return Result.success(list);
//        try{
//            System.out.println("get");
//            List<ChatMessage> list = chatMessageService.list();
//            System.out.println(list);
//            return Result.success(list);
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        return Result.error();
    }

    @PostMapping("/send")
    public void sendMsg(@RequestBody ArrayList<ChatMessage> list) {
        try{
            chatMessageService.saveBatch(list);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
